package exttable.testversioning.testversionrunner;

import exttable.view.ViewAnalysis;
import exttable.view.ViewVersion;
import utils.Localisation;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: Jun 16, 2010
 * Time: 10:00:39 AM
 * To change this template use File | Settings | File Templates.
 */
public class TestVersionsRenderer implements TableCellRenderer {
    public static final int ANALYSIS_NAME = 0;
    public static final int PHASE = 2;
    private JButton button;

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (column == ANALYSIS_NAME) {
            return getCellComponent((ViewAnalysis) table.getValueAt(row, 0));
        }
        if (column == PHASE) {
            return getCellComponent((ViewVersion) table.getValueAt(row, 2));
        }
        return null;
    }

    private Component getCellComponent(ViewAnalysis analysis) {
        button = new JButton(analysis.toString());
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
            }
        });
        return button;

    }

    private Component getCellComponent(ViewVersion version) {
        Component c;
        if (version == null || version.getVersionId() == null) {
            c = new JLabel(Localisation.getMessage("info.noversions"));
            return c;
        }
        c = new JLabel(version.toString());
        return c;
    }


}
